package com.jb.repair.fragment;

import android.annotation.TargetApi;
import android.app.Fragment;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.jb.repair.R;
import com.jb.repair.acticity.ActionRecordActivtity;
import com.jb.repair.acticity.BeRecordActivtity;
import com.jb.repair.acticity.BugRecordActivtity;
import com.jb.repair.acticity.ChangeRecordActivtity;
import com.jb.repair.acticity.CheckRecordActivtity;
import com.jb.repair.acticity.EquipInfoActivtity;
import com.jb.repair.acticity.ExceptionRecordActivtity;
import com.jb.repair.acticity.FssbIntroActivity;
import com.jb.repair.acticity.SpareEquipActivtity;
import com.jb.repair.adapter.BjsbAdapter;
import com.jb.repair.adapter.DzjlAdatper;
import com.jb.repair.adapter.EquipDataAdapter;
import com.jb.repair.adapter.FssbAdapter;
import com.jb.repair.adapter.JxjlAdatper;
import com.jb.repair.adapter.QxjlAdatper;
import com.jb.repair.adapter.RecordAdapter;
import com.jb.repair.adapter.SbzlAdapter;
import com.jb.repair.adapter.SpareEquipAdapter;
import com.jb.repair.adapter.TtjlAdatper;
import com.jb.repair.adapter.YcjlAdatper;
import com.jb.repair.adapter.YdjlAdatper;
import com.jb.repair.dao.Db;
import com.jb.repair.model.DzjlModel;
import com.jb.repair.model.EquipDataModel;
import com.jb.repair.model.FssbModel;
import com.jb.repair.model.JxjlModel;
import com.jb.repair.model.LedgerModel;
import com.jb.repair.model.QxjlModel;
import com.jb.repair.model.RecordModel;
import com.jb.repair.model.SbbdzdyModel;
import com.jb.repair.model.SbbjModel;
import com.jb.repair.model.SbzlModel;
import com.jb.repair.model.SpareEquipModel;
import com.jb.repair.model.TtjlModel;
import com.jb.repair.model.YcjlModel;
import com.jb.repair.model.YdjlModel;
import com.jb.repair.util.StringUtils;
import com.jb.repair.view.AttriTextView;
import com.jb.repair.view.ListViewInScroll;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by gaobin on 2015/10/23.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class LedgerFrament extends Fragment implements View.OnClickListener, AdapterView.OnItemClickListener {
    //    private AttriTextView tv_zhaugnye, tv_jizu, tv_sbmc, tv_azwz, tv_sspg, tv_sblx, tv_sbxh, tv_sccj, tv_sjsm;
//    private AttriTextView tv_scrq, tv_tyrq, tv_yxzt, tv_qbjyzq, tv_bfjyzq, tv_dydj, tv_tdlx, tv_ycsb, tv_kks, tv_fzr;
    private List<TextView> tvs = new ArrayList<TextView>();
    private ListViewInScroll lv_fssb, lv_bpsb, lv_sbzl, lv_ycjl, lv_qxjl, lv_jxjl, lv_dzjl, lv_ttjl, lv_ydjl;
    private ScrollView scrollView;
    private TextView tv0, tv1, tv2, tv3, tv4, tv5, tv6, tv7, tv8, tv9;
    private LinearLayout ll_info, ll_right, ll_left,ll_jscs;
    private TextView tv_name;
    private View v1, v2, v3, v4, v5, v6, v7, v8, v0;
    private AttriTextView tv_zhuanye, tv_sblx, tv_sccj, tv_tyrq, tv_zrr, tv_eq_code, tv_note;
    private AttriTextView tv_sbmc, tv_sbxh, tv_azwz, tv_yxzt, tv_eq_level;
    private TextView eq_tech_parameter;

    private List<FssbModel> fssbModelList = new ArrayList<FssbModel>();
    private List<SpareEquipModel> spareEquipModelList = new ArrayList<SpareEquipModel>();
    private List<EquipDataModel> equipDataModelList = new ArrayList<EquipDataModel>();
    private List<RecordModel> recordModelList = new ArrayList<RecordModel>();
    private RecordAdapter recordAdapter;
    private EquipDataAdapter equipDataAdapter;
    private FssbAdapter fssbAdapter;
    private SpareEquipAdapter spareEquipAdapter;
    private Db db;
    private String id = "";
    private String devName = "";
    private String layer_code = "";

    //11.4 设备备件
    private List<SbbjModel> sbbjModelList = new ArrayList<SbbjModel>();
    private BjsbAdapter bjsbAdapter;
    private String id1 = "";
    //设备资料
    private List<SbzlModel> sbzlModelList = new ArrayList<SbzlModel>();
    private SbzlAdapter sbzlAdapter;
    private String id2 = "";
    //异常记录
    private List<YcjlModel> ycjlModelList = new ArrayList<YcjlModel>();
    private YcjlAdatper ycjlAdatper;
    private String id3 = "";
    //缺陷记录
    private List<QxjlModel> qxjlModelList = new ArrayList<QxjlModel>();
    private QxjlAdatper qxjlAdatper;
    private String id4 = "";
    //检修记录
    private List<JxjlModel> jxjlModelList = new ArrayList<JxjlModel>();
    private JxjlAdatper jxjlAdatper;
    private String id5 = "";
    //动作记录
    private List<DzjlModel> dzjlModelList = new ArrayList<DzjlModel>();
    private DzjlAdatper dzjlAdatper;
    private String id6 = "";
    //投退记录
    private List<TtjlModel> ttjlModelList = new ArrayList<TtjlModel>();
    private TtjlAdatper ttjlAdatper;
    private String id7 = "";
    //异动记录
    private List<YdjlModel> ydjlModelList = new ArrayList<YdjlModel>();
    private YdjlAdatper ydjlAdatper;
    private String id8 = "";


    private List<Integer> heights = new ArrayList<Integer>();
    private List<String> sbcclist = new ArrayList<>();
    private String id_zhuanye;

    public LedgerFrament() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.frament_ledger, null);

        id = getArguments().getString("id");
        layer_code = getArguments().getString("layer_code");


        db = Db.getInstance(getActivity());
        initView(view);
        initData(view);
//--------------------------------------------------------------分割线以下  by zhangjin--------------------------------141-336
        //判断是根据设备id查找 还是根据layer_code查找
        if (!StringUtils.isNullOrEmpty(id)) {
            //根据设备查找
            Log.i("WPWPWPWPPWPW","根据ID查找");
            Log.i("WPWPWPWPPWPW","设备ID = "+id);
            // 拿到设备id上面的所有层级，取出最高等级的前三等级
            sbcclist.clear();
            String nameself = db.getName("eq_name", "TB_EQ_BASICINFO", "guid", id);
            sbcclist.add(nameself);
            String layercode = db.getName("layer_code", "TB_EQ_BASICINFO", "guid", id);
            String namelast = db.getName("layer_name", "TB_EQ_NAV", "layer_code", layercode);
            sbcclist.add(namelast);
            List<String> sbcc = getSbcc(layercode);
            String sbccName = getSbccName(sbcc);

            String form_CODE = db.getName2("CODE", "TB_SYS_CODE", "CODE_NAME", "基本信息");
//            String id_zhuanye = sbcclist.get(sbcclist.size() - 2);
            //根据设备id查找基本信息 设置基本信息表
            ll_info.setVisibility(View.VISIBLE);
            ll_jscs.setVisibility(View.VISIBLE);
            tv0.setVisibility(View.VISIBLE);
            v0.setVisibility(View.VISIBLE);
            LedgerModel lederModel = db.getLedgerbyId(id);
            tv_name.setText(sbccName+ "→" +lederModel.eq_name);
            tv_sbmc.setValue(lederModel.eq_name);
            String name1 = db.getName("place", "TB_SI_TASK_RESULT", "place_id", lederModel.eq_postion_id);
            tv_azwz.setValue(name1);
            String name2 = db.getName("eq_type_name", "TB_EQ_TYPE", "guid", lederModel.eq_type_id);
            tv_sblx.setValue(name2);
            String name5 = db.getName("eq_model_name", "TB_EQ_MODEL", "guid", lederModel.eq_model_id);
            tv_sbxh.setValue(name5);
            String name3 = db.getName("producer_name", "TB_EQ_PRODUCER", "guid", lederModel.eq_producer_id);
            tv_sccj.setValue(name3);
            if(!StringUtils.isNullOrEmpty(lederModel.eq_operation_date) && lederModel.eq_operation_date.length()>=11){
//                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
//                String time = simpleDateFormat.format(new Date().parse(lederModel.eq_operation_date));
                String time = lederModel.eq_operation_date.substring(0,11);
                tv_tyrq.setValue(time);
            }else {
                tv_tyrq.setValue(lederModel.eq_operation_date);
            }

            String name7 = db.getName("CODE_NAME", "TB_SYS_CODE", "CODE", lederModel.eq_status);
            tv_yxzt.setValue(name7);
            String name = db.getName("eq_dept", "TB_SI_TASK", "eq_dept_id", lederModel.eq_edetp_id);
//            String name = db.getName("layer_name", "TB_EQ_NAV", "guid", lederModel.eq_edetp_id);
            tv_zhuanye.setValue(name);
            String name4 = db.getName("PERS_NAME","TB_SYS_PERSON","GUID",lederModel.eq_supervisor_id);
            tv_zrr.setValue(name4);
            tv_eq_code.setValue( lederModel.eq_code);
            tv_note.setValue( lederModel.note);
            String name8 = db.getName("CODE_NAME", "TB_SYS_CODE", "CODE", lederModel.eq_level);
            tv_eq_level.setValue(name8);
            eq_tech_parameter.setText(lederModel.eq_tech_parameter);
            id_zhuanye = lederModel.eq_edetp_id;

            //
            List<SbbdzdyModel> sbbdzdyModelList = db.getSbbdzdyModel(form_CODE, id_zhuanye);
            int i = 1;
            for (SbbdzdyModel model1 : sbbdzdyModelList) {
                if (model1.is_show_eqbook.equals("T")) {
                    AttriTextView textview = new AttriTextView(getActivity());
                    if (i / 2 == 0) {
                        ll_left.addView(textview);
                    } else {
                        ll_right.addView(textview);
                    }

                        textview.setIsImp(false);
                    textview.setKey(model1.cus_name);
                    String zdyzdValue = db.getZdyzdValue(model1.guid, id);
                    textview.setValue(zdyzdValue);
                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    params.gravity = Gravity.RIGHT;
                    textview.setLayoutParams(params);
                }
            }


            //查找显示哪些详情页
            List<String> list = new ArrayList<>();
            List<String> listByZYid = db.getListByZYid(lederModel.eq_edetp_id);
            for (String string : listByZYid) {
                String name6 = db.getName("CODE_NAME", "TB_SYS_CODE", "CODE", string);
                list.add(name6);
            }
            for (String s : list) {
                Log.e("ledgerFrament", s.toString());
                if (s.equals(tv1.getText())) {
                    tv1.setVisibility(View.VISIBLE);
                    v1.setVisibility(View.VISIBLE);
                    lv_fssb.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv2.getText())) {
                    tv2.setVisibility(View.VISIBLE);
                    v2.setVisibility(View.VISIBLE);
                    lv_bpsb.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv3.getText())) {
                    tv3.setVisibility(View.VISIBLE);
                    v3.setVisibility(View.VISIBLE);
                    lv_sbzl.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv4.getText())) {
                    tv4.setVisibility(View.VISIBLE);
                    v4.setVisibility(View.VISIBLE);
                    lv_ycjl.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv5.getText())) {
                    tv5.setVisibility(View.VISIBLE);
                    v5.setVisibility(View.VISIBLE);
                    lv_qxjl.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv6.getText())) {
                    tv6.setVisibility(View.VISIBLE);
                    v6.setVisibility(View.VISIBLE);
                    lv_jxjl.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv7.getText())) {
                    tv7.setVisibility(View.VISIBLE);
                    v7.setVisibility(View.VISIBLE);
                    lv_dzjl.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv8.getText())) {
                    tv8.setVisibility(View.VISIBLE);
                    v8.setVisibility(View.VISIBLE);
                    lv_ttjl.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv9.getText())) {
                    tv9.setVisibility(View.VISIBLE);
                    lv_ydjl.setVisibility(View.VISIBLE);
                }
            }
            ycjlModelList = db.getYcjlById(id);
            Log.i("CCC",ycjlModelList.toString()+"CCCCCCC");
            sbzlModelList = db.getSbzlById(id);
            Log.i("CCC",sbzlModelList.toString()+"CCCCCCC");
            sbbjModelList = db.getSbbjById(id);
            fssbModelList = db.getFssbById(id);
            qxjlModelList = db.getQxjlById(id);
            jxjlModelList = db.getJxjlById(id);
            dzjlModelList = db.getDzjlById(id);
            ydjlModelList = db.getYdjlById(id);
            ttjlModelList = db.getTtjlById(id);

        } else if (!StringUtils.isNullOrEmpty(layer_code)) {
            //从层次编码跳转
            Log.i("WPWPWPWPPWPW","根据layer_code查找");
            //拿到layer_code上面的所有层级
            sbcclist.clear();
            String nameself = db.getName("layer_name", "TB_EQ_NAV", "layer_code", layer_code);
            sbcclist.add(nameself);
            List<String> sbcc = getSbcc(layer_code);
            String sbccName = getSbccName(sbcc);
            tv_name.setText(sbccName);

            //根据layer_code查找集合
            Log.e("ledgerFrament", "layer_code");
            ycjlModelList = db.getYcjlByCode(layer_code);
            sbzlModelList = db.getSbzlByCode(layer_code);
            sbbjModelList = db.getSbbjByCode(layer_code);
            fssbModelList = db.getFssbByCode(layer_code);
            qxjlModelList = db.getQxjlByCode(layer_code);
            jxjlModelList = db.getJxjlByCode(layer_code);
            dzjlModelList = db.getDzjlByCode(layer_code);
            ydjlModelList = db.getYdjlByCode(layer_code);
            ttjlModelList = db.getTtjlByCode(layer_code);

            //根据layer_code读取出需要显示哪些表
            List<String> list1 = db.getListByLayerCode(layer_code);
            List<String> list2 = new ArrayList<>();
            for (String string : list1) {
                String name = db.getName("CODE_NAME", "TB_SYS_CODE", "CODE", string);
                list2.add(name);
            }
            for (String s : list2) {
                Log.e("ledgerFrament", s.toString());
                if (s.equals(tv0.getText())) {
                    tv0.setVisibility(View.VISIBLE);
                    v0.setVisibility(View.VISIBLE);
                    ll_info.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv1.getText())) {
                    tv1.setVisibility(View.VISIBLE);
                    v1.setVisibility(View.VISIBLE);
                    lv_fssb.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv2.getText())) {
                    tv2.setVisibility(View.VISIBLE);
                    v2.setVisibility(View.VISIBLE);
                    lv_bpsb.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv3.getText())) {
                    tv3.setVisibility(View.VISIBLE);
                    v3.setVisibility(View.VISIBLE);
                    lv_sbzl.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv4.getText())) {
                    tv4.setVisibility(View.VISIBLE);
                    v4.setVisibility(View.VISIBLE);
                    lv_ycjl.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv5.getText())) {
                    tv5.setVisibility(View.VISIBLE);
                    v5.setVisibility(View.VISIBLE);
                    lv_qxjl.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv6.getText())) {
                    tv6.setVisibility(View.VISIBLE);
                    v6.setVisibility(View.VISIBLE);
                    lv_jxjl.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv7.getText())) {
                    tv7.setVisibility(View.VISIBLE);
                    v7.setVisibility(View.VISIBLE);
                    lv_dzjl.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv8.getText())) {
                    tv8.setVisibility(View.VISIBLE);
                    v8.setVisibility(View.VISIBLE);
                    lv_ttjl.setVisibility(View.VISIBLE);
                }
                if (s.equals(tv9.getText())) {
                    tv9.setVisibility(View.VISIBLE);
                    lv_ydjl.setVisibility(View.VISIBLE);
                }
            }
        }
//----------------------------------分割线以上 by zhangjin ---------------------------------------------141-336

        fssbAdapter = new FssbAdapter(getActivity(), fssbModelList);
        lv_fssb.setAdapter(fssbAdapter);


        // 11.4
        //备品设备
        //id1 = "6A802EB6-8A66-4338-BAFE-6AB9DA2F6516-00125";
        bjsbAdapter = new BjsbAdapter(getActivity(), sbbjModelList);
        lv_bpsb.setAdapter(bjsbAdapter);


        //资料设备
        // id2 = "c34a7eafb11111e49d5a4439c454643f";
        sbzlAdapter = new SbzlAdapter(getActivity(), sbzlModelList);
        lv_sbzl.setAdapter(sbzlAdapter);
        Log.i("ABC",sbzlModelList.toString()+"___AAAAAAAAAAAAAAAAAAAAAAAAAAA");

        //异常记录
        //  id3 = "c34a7eafb11111e49d5a4439c454643f";
        ycjlAdatper = new YcjlAdatper(getActivity(), ycjlModelList);
        lv_ycjl.setAdapter(ycjlAdatper);
        Log.i("ABC",ycjlModelList.toString()+"___BBBBBBBBBBBBBBBBBBBBBBB");

        //缺陷记录
        // id4 = "c34e19c7b11111e49d5a4439c454643f";
        qxjlAdatper = new QxjlAdatper(getActivity(), qxjlModelList);
        lv_qxjl.setAdapter(qxjlAdatper);
        //检修记录
        //  id5 = "8e3fd6cdf9a311e4aab9206a8a562037";
        jxjlAdatper = new JxjlAdatper(getActivity(), jxjlModelList);
        lv_jxjl.setAdapter(jxjlAdatper);
        //动作记录
        //   id6 = "c7f7e959b11111e49d5a4439c454643f";
        dzjlAdatper = new DzjlAdatper(getActivity(), dzjlModelList);
        lv_dzjl.setAdapter(dzjlAdatper);
        //投退记录
        //  id7 = "6A802EB6-8A66-4338-BAFE-6AB9DA2F6516-00132";
        ttjlAdatper = new TtjlAdatper(getActivity(), ttjlModelList);
        Log.e("abcdefg", String.valueOf(ttjlModelList.size()));
        lv_ttjl.setAdapter(ttjlAdatper);
        //异动记录
        //   id8 = "6A802EB6-8A66-4338-BAFE-6AB9DA2F6516-00199";
        ydjlAdatper = new YdjlAdatper(getActivity(), ydjlModelList);
        lv_ydjl.setAdapter(ydjlAdatper);


        lv_fssb.setOnItemClickListener(this);
        lv_bpsb.setOnItemClickListener(this);
        lv_sbzl.setOnItemClickListener(this);
        lv_ycjl.setOnItemClickListener(this);
        lv_qxjl.setOnItemClickListener(this);
        lv_jxjl.setOnItemClickListener(this);
        lv_dzjl.setOnItemClickListener(this);
        lv_ttjl.setOnItemClickListener(this);
        lv_ydjl.setOnItemClickListener(this);
        Log.e("1231", "设置监听");
        return view;
    }


    private void initData(View v) {
    }

    private void initView(View v) {
        lv_fssb = (ListViewInScroll) v.findViewById(R.id.lv_fushushebei);
        lv_bpsb = (ListViewInScroll) v.findViewById(R.id.lv_beiyongshebei);
        lv_sbzl = (ListViewInScroll) v.findViewById(R.id.lv_shebeiziliao);
        lv_ycjl = (ListViewInScroll) v.findViewById(R.id.lv_yichangjilu);
        lv_qxjl = (ListViewInScroll) v.findViewById(R.id.lv_quexianjilu);
        lv_jxjl = (ListViewInScroll) v.findViewById(R.id.lv_jianxiujilu);
        lv_dzjl = (ListViewInScroll) v.findViewById(R.id.lv_dongzuojilu);
        lv_ttjl = (ListViewInScroll) v.findViewById(R.id.lv_toutuijilu);
        lv_ydjl = (ListViewInScroll) v.findViewById(R.id.lv_yidongjilu);
        scrollView = (ScrollView) v.findViewById(R.id.scrollView);
        ll_info = (LinearLayout) v.findViewById(R.id.ll_equip_info);
        ll_left = (LinearLayout) v.findViewById(R.id.ll_left);
        ll_right = (LinearLayout) v.findViewById(R.id.ll_right);
        ll_jscs = (LinearLayout) v.findViewById(R.id.ll_jscs);
        eq_tech_parameter = (TextView) v.findViewById(R.id.tv_jscs);

        tv_name = (TextView) v.findViewById(R.id.tv_equip_name);
        tv_sbmc = (AttriTextView) v.findViewById(R.id.tv_sbmc);
        tv_zhuanye = (AttriTextView) v.findViewById(R.id.tv_zhuanye);
        tv_azwz = (AttriTextView) v.findViewById(R.id.tv_azwz);
        tv_eq_code = (AttriTextView) v.findViewById(R.id.tv_eq_code);
        tv_note = (AttriTextView) v.findViewById(R.id.tv_note);
        tv_eq_level = (AttriTextView) v.findViewById(R.id.tv_eq_level);
//        eq_tech_parameter = (AttriTextView) v.findViewById(R.id.eq_tech_parameter);

        tv_sblx = (AttriTextView) v.findViewById(R.id.tv_sblx);
        tv_sbxh = (AttriTextView) v.findViewById(R.id.tv_sbxh);
        tv_sccj = (AttriTextView) v.findViewById(R.id.tv_sccj);
        tv_yxzt = (AttriTextView) v.findViewById(R.id.tv_yxzt);
        tv_tyrq = (AttriTextView) v.findViewById(R.id.tv_tyrq);
        tv_zrr = (AttriTextView) v.findViewById(R.id.tv_zrr);
        v1 = v.findViewById(R.id.v1);
        v2 = v.findViewById(R.id.v2);
        v3 = v.findViewById(R.id.v3);
        v4 = v.findViewById(R.id.v4);
        v5 = v.findViewById(R.id.v5);
        v6 = v.findViewById(R.id.v6);
        v7 = v.findViewById(R.id.v7);
        v8 = v.findViewById(R.id.v8);
        v0 = v.findViewById(R.id.v0);


        ininMenuBar(v);

        //scrollview滑动停止监听，
        scrollView.setOnTouchListener(new View.OnTouchListener() {
            private int lastY = 0;
            private int touchEventId = -9983761;

            Handler handler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    View scroller = (View) msg.obj;
                    if (msg.what == touchEventId) {
                        if (lastY == scroller.getScrollY()) {
                            handleStop(scroller);
                        } else {
                            handler.sendMessageDelayed(handler.obtainMessage(touchEventId, scroller), 5);
                            lastY = scroller.getScrollY();
                        }
                    }
                }
            };

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    handler.sendMessageDelayed(handler.obtainMessage(touchEventId, v), 5);
                }
                return false;
            }

            //这里写真正的事件
            private void handleStop(Object view) {
                setMenuBar(scrollView.getScrollY());
            }
        });
    }

    private void setMenuBar(int height) {
        measureHeight();
        if (height == 0) {
            menuSelecte(0);
            return;
        }
        for (int i = 0; i < heights.size(); i++) {
            if (height < heights.get(i)) {
                menuSelecte(i + 1);
                return;
            }
        }
    }

    private void ininMenuBar(View v) {
        tv0 = (TextView) v.findViewById(R.id.tv_info);
        tv1 = (TextView) v.findViewById(R.id.tv_belong);
        tv2 = (TextView) v.findViewById(R.id.tv_reserve);
        tv3 = (TextView) v.findViewById(R.id.tv_data);
        tv4 = (TextView) v.findViewById(R.id.tv_abnormal);
        tv5 = (TextView) v.findViewById(R.id.tv_defect);
        tv6 = (TextView) v.findViewById(R.id.tv_repair);
        tv7 = (TextView) v.findViewById(R.id.tv_action);
        tv8 = (TextView) v.findViewById(R.id.tv_import);
        tv9 = (TextView) v.findViewById(R.id.tv_yidong);
        tv0.setOnClickListener(this);
        tv1.setOnClickListener(this);
        tv2.setOnClickListener(this);
        tv3.setOnClickListener(this);
        tv4.setOnClickListener(this);
        tv5.setOnClickListener(this);
        tv6.setOnClickListener(this);
        tv7.setOnClickListener(this);
        tv8.setOnClickListener(this);
        tv9.setOnClickListener(this);
        tvs.add(tv0);
        tvs.add(tv1);
        tvs.add(tv2);
        tvs.add(tv3);
        tvs.add(tv4);
        tvs.add(tv5);
        tvs.add(tv6);
        tvs.add(tv7);
        tvs.add(tv8);
        tvs.add(tv9);
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    private void menuSelecte(int m) {
        for (int i = 0; i < 10; i++) {
            TextView tv = tvs.get(i);
            if (i == m) {
                tv.setBackgroundResource(R.drawable.textview_selected);
                tv.setTextColor(getActivity().getResources().getColor(R.color.white_font));
            } else {
                tv.setBackgroundResource(R.drawable.textview_unselet);
                tv.setTextColor(getActivity().getResources().getColor(R.color.black_text));
            }
        }
    }

    private void measureHeight() {
        if (heights == null || heights.size() == 0) {
            heights.add(ll_info.getHeight());
            heights.add(ll_info.getHeight() + lv_fssb.getHeight());
            heights.add(ll_info.getHeight() + lv_fssb.getHeight() + lv_bpsb.getHeight());
            heights.add(ll_info.getHeight() + lv_fssb.getHeight() + lv_bpsb.getHeight() + lv_sbzl.getHeight());
            heights.add(ll_info.getHeight() + lv_fssb.getHeight() + lv_bpsb.getHeight() + lv_sbzl.getHeight() + lv_ycjl.getHeight());
            heights.add(ll_info.getHeight() + lv_fssb.getHeight() + lv_bpsb.getHeight() + lv_sbzl.getHeight() + lv_ycjl.getHeight() + lv_qxjl.getHeight());
            heights.add(ll_info.getHeight() + lv_fssb.getHeight() + lv_bpsb.getHeight() + lv_sbzl.getHeight() + lv_ycjl.getHeight() + lv_qxjl.getHeight() + lv_jxjl.getHeight());
            heights.add(ll_info.getHeight() + lv_fssb.getHeight() + lv_bpsb.getHeight() + lv_sbzl.getHeight() + lv_ycjl.getHeight() + lv_qxjl.getHeight() + lv_jxjl.getHeight());
            heights.add(ll_info.getHeight() + lv_fssb.getHeight() + lv_bpsb.getHeight() + lv_sbzl.getHeight() + lv_ycjl.getHeight() + lv_qxjl.getHeight() + lv_jxjl.getHeight() + lv_ttjl.getHeight());
        }
    }

    @Override
    public void onClick(View v) {
        measureHeight();
        switch (v.getId()) {
            case R.id.tv_info:
                menuSelecte(0);
                scrollView.smoothScrollTo(0, 0);
                break;
            case R.id.tv_belong:
                menuSelecte(1);
                scrollView.smoothScrollTo(0, heights.get(0));
                break;
            case R.id.tv_reserve:
                scrollView.smoothScrollTo(0, heights.get(1));
                menuSelecte(2);
                break;
            case R.id.tv_data:
                scrollView.smoothScrollTo(0, heights.get(2));
                menuSelecte(3);
                break;
            case R.id.tv_abnormal:
                scrollView.smoothScrollTo(0, heights.get(3));
                menuSelecte(4);
                break;
            case R.id.tv_defect:
                scrollView.smoothScrollTo(0, heights.get(4));
                menuSelecte(5);
                break;
            case R.id.tv_repair:
                scrollView.smoothScrollTo(0, heights.get(5));
                menuSelecte(6);
                break;
            case R.id.tv_action:
                scrollView.smoothScrollTo(0, heights.get(6));
                menuSelecte(7);
                break;
            case R.id.tv_import:
                scrollView.smoothScrollTo(0, heights.get(7));
                menuSelecte(8);
                break;
            case R.id.tv_yidong:
                scrollView.smoothScrollTo(0, heights.get(8));
                menuSelecte(9);
                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        //Log.e("1231", "xiangy");
        if (position > 0) {

            switch (parent.getId()) {
                case R.id.lv_fushushebei:
                    Intent intent = new Intent(getActivity(), FssbIntroActivity.class);
                    intent.putExtra("fssb", fssbModelList.get(position - 1));
                    intent.putExtra("id_zhuanye",id_zhuanye);
                    startActivity(intent);
                    break;
                case R.id.lv_beiyongshebei:
                    Intent spareintent = new Intent(getActivity(), SpareEquipActivtity.class);
                    spareintent.putExtra("bjsb", sbbjModelList.get(position - 1));
                    spareintent.putExtra("id_zhuanye",id_zhuanye);
                    startActivity(spareintent);
                    break;
                case R.id.lv_shebeiziliao:
                    Intent ziliaointent = new Intent(getActivity(), EquipInfoActivtity.class);
                    ziliaointent.putExtra("sbzl", sbzlModelList.get(position - 1));
                    ziliaointent.putExtra("id_zhuanye",id_zhuanye);
                    startActivity(ziliaointent);
                    break;
                case R.id.lv_yichangjilu:
                    Intent excepintent = new Intent(getActivity(), ExceptionRecordActivtity.class);
                    excepintent.putExtra("ycjl", ycjlModelList.get(position - 1));
                    excepintent.putExtra("id_zhuanye",id_zhuanye);
                    startActivity(excepintent);
                    break;
                case R.id.lv_quexianjilu:
                    Intent bugintent = new Intent(getActivity(), BugRecordActivtity.class);
                    bugintent.putExtra("qxjl", qxjlModelList.get(position - 1));
                    bugintent.putExtra("id_zhuanye",id_zhuanye);
                    startActivity(bugintent);
                    break;
                case R.id.lv_jianxiujilu:
                    Intent repairintent = new Intent(getActivity(), CheckRecordActivtity.class);
                    repairintent.putExtra("jxjl", jxjlModelList.get(position - 1));
                    repairintent.putExtra("id_zhuanye",id_zhuanye);
                    startActivity(repairintent);
                    break;
                case R.id.lv_dongzuojilu:
                    Intent actionintent = new Intent(getActivity(), ActionRecordActivtity.class);
                    actionintent.putExtra("dzjl", dzjlModelList.get(position - 1));
                    actionintent.putExtra("id_zhuanye", id_zhuanye);
                    startActivity(actionintent);
                    break;
                case R.id.lv_toutuijilu:
                    Intent exitintent = new Intent(getActivity(), BeRecordActivtity.class);
                    exitintent.putExtra("ttjl", ttjlModelList.get(position - 1));
                    exitintent.putExtra("id_zhuanye",id_zhuanye);
                    startActivity(exitintent);
                    break;
                case R.id.lv_yidongjilu:
                    Intent yiintent = new Intent(getActivity(), ChangeRecordActivtity.class);
                    yiintent.putExtra("ydjl", ydjlModelList.get(position - 1));
                    yiintent.putExtra("id_zhuanye",id_zhuanye);
                    startActivity(yiintent);
                    break;

            }
        }
    }

    //------------------------------------------------------------------分割线以下by zhangjin----------------655-685
    //这两个方法是获取前3个层次 一块使用
    public List<String> getSbcc(String layer_code) {

        String s1 = db.getName("parent_id", "TB_EQ_NAV", "layer_code", layer_code);
        if (!StringUtils.isNullOrEmpty(s1)) {
            String name1 = db.getName("layer_name", "TB_EQ_NAV", "layer_code", s1);
            sbcclist.add(name1);
            getSbcc(s1);
        }
        return sbcclist;
    }

    public String getSbccName(List<String> list) {
        int size = list.size();
        if (size == 0) {
            return "";
        } else if (size == 1) {
            return sbcclist.get(0);
        } else if (size == 2) {
            return sbcclist.get(0);
        } else if (size == 3) {
            return sbcclist.get(1) + "→" + sbcclist.get(0);
        } else if (size == 4) {
            return sbcclist.get(2) + "→" + sbcclist.get(1) + "→" + sbcclist.get(0);
        } else if (size > 4) {
            return sbcclist.get(size - 2) + "→" + sbcclist.get(size - 3) + "→" + sbcclist.get(size - 4);
        }
        return "";
    }
}
